home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / QuickTime / QuickTime VR / Make QTVR Object / Event.c < prev    next >
Encoding:
Text File  |  2000-09-28  |  6.1 KB  |  318 lines  |  [TEXT/KAHL]

  1. //
  2. //         This is sample code which will make QTVR object movies from Linear QuickTime movies.
  3. //
  4. //        © 1991-1996 Apple Computer, Inc.  All rights reserved.
  5. //
  6.  
  7. #include "MakeQTVRObject.h"
  8. #include "extern.h" 
  9.  
  10.  
  11. /***** DoEvent *****/
  12. void    MainLoop()
  13. {
  14.     char    theChar,theChar2;
  15.     RgnHandle        theMouseRgn;
  16.     EventRecord        theEvent;
  17.  
  18.     theMouseRgn = NewRgn();
  19.     while (gDone == false)
  20.         {
  21.         WaitNextEvent(everyEvent, &theEvent, nil, nil);
  22.             
  23.         if (!CheckMovieControllers(&theEvent))
  24.             {
  25.             switch (theEvent.what)
  26.                 {
  27.                 case kHighLevelEvent:
  28.                     AEProcessAppleEvent(&theEvent);
  29.                     break;
  30.                 case nullEvent:
  31.                     DoNull();
  32.                     break;
  33.                 case mouseDown:
  34.                     DoMouseDown(&theEvent);
  35.                     break;
  36.                 case keyDown:
  37.                 case autoKey:
  38.                     SetupMenus();
  39.                     theChar = theEvent.message & charCodeMask;
  40.                     theChar2 = (theEvent.message & keyCodeMask) >> 8;
  41.                     if (( theEvent.modifiers & cmdKey) != 0) 
  42.                         DoMenuChoice( MenuKey( theChar));
  43.                     else
  44.                         KeyDown(theChar,theChar2);
  45.                     break;
  46.                 case updateEvt:
  47.                     DoUpdate(&theEvent);
  48.                     break;
  49.                 }
  50.             }
  51.             
  52.         }
  53.     DisposeRgn(theMouseRgn);
  54.     
  55. }
  56.  
  57. Boolean CheckMovieControllers(EventRecord *theEvent)
  58. {    
  59.     WindowPtr        currWindow;
  60.     MovieInstance    *theInstance;
  61.     GWorldPtr         saveGW, movieGW;
  62.     GDHandle         saveGD, movieGD;
  63.     ComponentResult eventHandled = false;    
  64.     Boolean            isOS = false;
  65.  
  66.     GetGWorld(&saveGW, &saveGD);
  67.     
  68.     
  69.     currWindow = FrontWindow();
  70.     while(currWindow)
  71.          {    
  72.          theInstance = GetMovieInstanceFromWindow(currWindow);
  73.         if (theInstance) 
  74.             {
  75.             GetMovieGWorld(theInstance->movie, &movieGW, &movieGD);
  76.             SetGWorld(movieGW, movieGD);
  77.             eventHandled = MCIsPlayerEvent( theInstance->movieController, theEvent);
  78.             MoviesTask(theInstance->movie,1);
  79.             SetGWorld(saveGW, saveGD);
  80.             if (eventHandled != 0)
  81.                 return eventHandled;
  82.             }
  83.         currWindow = (WindowPtr)(((WindowRecord*)currWindow)->nextWindow);
  84.         }
  85.     SetGWorld(saveGW, saveGD);
  86.     
  87.     return false;
  88. }
  89.  
  90. void    DoUpdate(EventRecord        *theEvent)
  91. {
  92.  
  93.     CWindowPtr    whichWindow;
  94.     
  95.     whichWindow = (CWindowPtr)theEvent->message;
  96.     SetGWorld(whichWindow,nil);
  97.     BeginUpdate((WindowPtr)whichWindow);
  98.     
  99.     EndUpdate((WindowPtr)whichWindow);
  100. }
  101.  
  102. /***** DoMouseDown *****/
  103. void    DoMouseDown(EventRecord        *theEvent)
  104. {
  105.     WindowPtr    whichWindow;
  106.     short int    thePart;
  107.     long int    menuChoice;
  108.  
  109.     thePart = FindWindow(theEvent->where, &whichWindow);
  110.     
  111.     
  112.     switch (thePart)
  113.     {
  114.         case inMenuBar:
  115.             SetupMenus();
  116.             menuChoice = MenuSelect(theEvent->where);
  117.             DoMenuChoice(menuChoice);
  118.             break;
  119.         case inSysWindow:
  120.             SystemClick(theEvent, whichWindow);
  121.             break;
  122.         case inDrag:
  123.             SelectWindow(whichWindow);
  124.             SetGWorld((CWindowPtr)whichWindow,nil);
  125.             DragWindow(whichWindow, theEvent->where, &qd.screenBits.bounds);
  126.             break;
  127.         case inGrow:
  128.             break;
  129.         case inZoomIn:
  130.         case inZoomOut:
  131.             
  132.             break;
  133.         case inGoAway:
  134.             SelectWindow(whichWindow);
  135.             SetGWorld((CWindowPtr)whichWindow,nil);
  136.             CloseMovie(whichWindow);
  137.             break;
  138.         case inContent:
  139.             if (whichWindow != FrontWindow())
  140.                   SelectWindow(whichWindow);
  141.                 break;
  142.     
  143.     }    
  144. }
  145.  
  146. void    DoMenuChoice(long menuResult)
  147. {
  148.     short            menuID, menuItem, daRefNum;
  149.     Str255            daName;
  150.     MovieInstance    *theInstance;
  151.  
  152.     theInstance = GetMovieInstanceFromWindow(FrontWindow());
  153.     SetCursor(&qd.arrow);
  154.     
  155.     menuID = HiWord(menuResult);    /* Use macros for efficiency to get */
  156.     menuItem = LoWord(menuResult);    /* menu item number and menu number. */
  157.  
  158.     switch (menuID) {
  159.  
  160.         case appleID:
  161.             switch (menuItem) {
  162.                 case iAbout:    /* Bring up alert for About. */
  163.                     About();
  164.                     break;
  165.                 default:        /* All non-About items in this menu are DAs. */
  166.                     GetItem(GetMHandle(appleID), menuItem, daName);
  167.                     daRefNum = OpenDeskAcc(daName);
  168.                     break;
  169.             }
  170.             break;
  171.         
  172.         case fileID:
  173.             switch (menuItem) {
  174.                 case iQuit:
  175.                     gDone = true;
  176.                     break;
  177.                 case iClose:    
  178.                     CloseMovie(FrontWindow());
  179.                     break;
  180.                 case iOpen:
  181.                     {
  182.                     FSSpec    theSpec;
  183.                     if(GetAMovie(&theSpec)) 
  184.                         OpenMovie(&theSpec);
  185.                     }
  186.                     break;
  187.                 case iDrop:
  188.                     gPrefInf.dropMode = !gPrefInf.dropMode;
  189.                     SavePrefs();
  190.                     break;
  191.                 case iSetPrefs:
  192.                     HandleMovieFormatDialog (theInstance,false);
  193.                     SavePrefs();
  194.                     break;
  195.                     
  196.             }
  197.             break;
  198.             
  199.         case editID:
  200.             switch (menuItem) {
  201.                 case iMakeObject:
  202.                     {
  203.                     OSErr    err;    
  204.  
  205.                     if(!theInstance) return;
  206.                     err = HandleMovieFormatDialog (theInstance,true);
  207.                     if(!err)
  208.                         {
  209.                         theInstance->isObjectMovie = true;
  210.                         SavePrefs();
  211.                         }
  212.                     }
  213.                     break;
  214.                 case iDeleteObject:
  215.                     {
  216.                     OSErr    err;    
  217.                     if(!theInstance || 
  218.                         !UserQuestion("\pAre you sure that you want to turn this object movie into a QuickTime movie?")) 
  219.                         return;
  220.                     err = DeleteQTVRObjectFileFormat1x0 (
  221.                                 theInstance->movie,
  222.                                 theInstance->movieResFile,
  223.                                 theInstance->movieResID,
  224.                                 theInstance->spec);
  225.  
  226.                     if(!err)
  227.                         {
  228.                         FSSpec tempSpec = theInstance->spec;
  229.                         CloseMovie (FrontWindow ());
  230.                         OpenMovie (&tempSpec);
  231.                         theInstance->isObjectMovie = false;
  232.                         }
  233.                     }
  234.                     break;
  235.                 case iSetPoster:
  236.                     DoSetStartUpView (theInstance);
  237.                     SavePrefs();
  238.                     break;
  239.                 case iShowPoster:
  240.                     ReopenMovie (theInstance);
  241.                     break;
  242.             }
  243.         
  244.         }
  245.  
  246.     HiliteMenu(0);        /* Unhighlight what MenuSelect (or MenuKey) hilited. */
  247. }
  248.  
  249. /***** Show about Dialog *****/
  250. void    About()
  251. {
  252.     short    itemHit;
  253.     DialogPtr    myDlg;
  254.     Boolean    done = false;
  255.     
  256.     myDlg = GetNewDialog( kAboutDLOG, 0, (WindowPtr) -1);
  257.     SetDialogDefaultItem(myDlg,kDefaultOK);
  258.     
  259.     while ( !done)
  260.         {
  261.         ModalDialog( 0, &itemHit );
  262.         switch ( itemHit ) 
  263.             {
  264.             case kDefaultOK:
  265.                 done = true;
  266.                 break;
  267.             }
  268.         } 
  269.     DisposDialog( myDlg);
  270.  
  271. }
  272.  
  273.  
  274.  
  275.  
  276. void    KeyDown(char    theChar,char    theChar2)
  277. {
  278.  
  279. }
  280.  
  281.  
  282.  
  283. void    DoNull()
  284. {
  285.     MyMoviesTask(FrontWindow());
  286. }
  287.  
  288.  
  289.  
  290. void MyMoviesTask(WindowPtr    theWindow)
  291. {    
  292.     MovieInstance    *theInstance;
  293.     Point pt;
  294.     GWorldPtr saveGW, movieGW;
  295.     GDHandle saveGD, movieGD;
  296.         
  297.     if(!theWindow)
  298.         return;
  299.         
  300.     theInstance = GetMovieInstanceFromWindow(theWindow);
  301.     if (!theInstance) 
  302.         return;
  303.         
  304.     GetGWorld(&saveGW, &saveGD);
  305.     GetMovieGWorld(theInstance->movie, &movieGW, &movieGD);
  306.     SetGWorld(movieGW, movieGD);
  307.     
  308.     GetMouse(&pt);
  309.     if (!PtInMovie(theInstance->movie,pt))
  310.         InitCursor();
  311.     MoviesTask(theInstance->movie,1);
  312.     SetGWorld(saveGW, saveGD);
  313. }
  314.  
  315.  
  316.  
  317.  
  318.